<?php

namespace addons\qingdongams\model;

use app\admin\model\AuthGroup;
use think\Model;
use traits\model\SoftDelete;

/**
 *员工部门表
 */
class StaffDepartment Extends Model {
	use SoftDelete;
    // 表名,不含前缀
    protected $name = 'qingdongams_staff_department';
	// 开启自动写入时间戳字段
	protected $autoWriteTimestamp = 'int';
	// 定义时间戳字段名
	protected $createTime = 'createtime';
	protected $updateTime = 'updatetime';
	protected $deleteTime = 'deletetime';


	//员工业绩
	public function achievement() {
		return $this->belongsTo(Achievement::class, 'id', 'obj_id')->where(['type' => 2]);
	}


	//获取部门列表
	public static function getDepartmentList() {

	}

	//获取部门及所有下级部门
	public static function getDepartmentLowerId($l_ids,$top=true){
		$ids=self::where(['pid' =>['in',$l_ids]])->column('id');
		if ($ids) {
			$w_ids = self::getDepartmentLowerId($ids,false);
			$ids   = array_merge($ids, $w_ids);
		}else{
			$ids=[];
		}
		if($top){
			$ids=array_merge($ids,$l_ids);
		}
		return $ids;
	}


    //获取部门列表
    public static function getList()
    {
        return self::where([])->field('id,name')->select();
    }
}
